/*	Copyright 2007 - Xavier Baro (xbaro@cvc.uab.cat)

	This file is part of eapmlib.

    Eapmlib is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or any 
	later version.

    Eapmlib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __THRCLASSIFIER_H__
#define __THRCLASSIFIER_H__

#include "EvolutiveLib.h"
#include "Classifier.h"
#include "Feature.h"

namespace Evolutive {

	//! Defines the posible actions to perform when the feature value is equal to the threshold
	enum EVOLUTIVELIB_API THRCLASS_EQTHR {EQTHR_ZERO,EQTHR_POS,EQTHR_NEG};

	class EVOLUTIVELIB_API CThrClassifier : public CClassifier
	{
		//! Methods
	public:
		//! Default constructor		
		CThrClassifier(void);

		//! Default destructor
		virtual ~CThrClassifier(void);		

#ifdef USE_OPENCV
		//! Returns the class name (From base class)
		virtual string GetClassNameID(void) {return "CThrClassifier";}

		//! Classify a given data (From base class)
		virtual double Apply(CData *InputData);

		//! Sets the feature parameters from a chromosome (from base class)
		virtual void SetFeatureParameters(CChromosome *C);

		//! Returns the feature parameters that defines the classifier (from base class)
		virtual void GetFeatureParameters(int &NumParameters,double **Parameters);

		//! Verify if a certain Chromosome is a valid solution (from base class)
		virtual bool IsValid(CChromosome *C);

		//! Point to the given feature
		void SetFeature(CFeature *Feature);

		//! Sets a threshold value
		void SetThreshold(double Threshold);

		//! Sets the default action in case of threshold value
		void SetThrEqualValueAction(THRCLASS_EQTHR Option);

		//! Return a pointer to the feature
		CFeature *GetFeature(void);

		//! Return the threshold
		double GetThreshold(void);

		//! Assigns the polarity value
		void SetPolarity(int Polarity);
								
	protected:
		//! Save or recover the data to/from a file (from base class)
		virtual void Serialize(std::fstream &fs,bool Saving);

#endif //USE_OPENCV					
		//! Attributes
	protected:		
		//! Pointer to a feature
		CFeature *m_Feature;

		//! Threshold value
		double m_Threshold;

		//! Polarity value
		int m_Polarity;

		//! Decision in the case of a feature value equal to the defined threshold
		THRCLASS_EQTHR m_EqThrAction;

		//! Pointer to an auxiliary self-created feature (used when the object is loaded)
		CFeature *m_FeatureAux;
	};	
}

#endif // __THRCLASSIFIER_H__
